# https://leetcode.cn/problems/longest-substring-without-repeating-characters/submissions/558747165/


class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        a = [0] * 256  
        l = 0 
        r = 0 
        ans = 0 
        
        while r < len(s):
            a[ord(s[r])] += 1
            while a[ord(s[r])] > 1:
                a[ord(s[l])] -= 1
                l += 1
            ans = max(ans, r - l + 1)
            r += 1
        
        return ans
